import { createRouter, createWebHistory } from "vue-router";
import bian from "@/router/router-modules/bian";
import li from "@/router/router-modules/li";
import zhai from "@/router/router-modules/zhai";
import duan from "@/router/router-modules/duan";
import yan from "@/router/router-modules/yan";
import xiang from "@/router/router-modules/xiang";
import loginreg from "@/router/router-modules/loginreg";
import long from "@/router/router-modules/long";
import jun from "@/router/router-modules/jun";
import feng from "@/router/router-modules/feng";
const routes = [
  ...feng,
  ...jun,
  ...long,
  ...xiang,
  ...loginreg,
  {
    path: "/home",
    name: "home",
    meta: {
      auth: true,
    },
    component: () => import("@/views/HomeView.vue"),
    children: [...bian, ...li, ...zhai, ...duan, ...yan],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/LoginView.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

router.beforeEach((to, from, next) => {
  // ...
  // 返回 false 以取消导航

  if (to.path == "/") {
    router.push({ path: "/tips1" });
  } else if (to.path == "/home") {
    //判断有无token 无token去登陆 router.push({path:'/login'}) 有token进首页next()
    next();
  } else {
    next();
  }
  // return false
});

export default router;
